package example;

import config.ProjectConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

    public static void main(String[] args) {
    	// 创建spring上下文实例
    	// var context = new AnnotationConfigApplicationContext();
    	// AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    	// 以配置类为参数创建spring上下文实例
    	AnnotationConfigApplicationContext context = 
    			new AnnotationConfigApplicationContext(ProjectConfig.class);
        // Parrot p = new Parrot();
    	//从Spring上下文中获取Parrot类型的bean实例
        Parrot p = context.getBean(Parrot.class);
    	// Parrot p = context.getBean("parrot1", Parrot.class);
    	Parrot p2 = context.getBean("abc", Parrot.class);
        System.out.println(p.getName());
        System.out.println(p2.getName());
        String s = context.getBean(String.class);
        System.out.println(s);
        Integer n = context.getBean(Integer.class);
        System.out.println(n);
        
        // 获取所有 bean 的名称
        String[] beanNames = context.getBeanDefinitionNames();
        
        // 打印所有 bean 的名称
        System.out.println("Beans in the context:");
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }
        // 关闭应用程序上下文
        context.close();
      }
}
